﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Data.GameData.GameMap;

namespace Data.GameData
{
    public class MapObject : GameObject, ICloneable
    {
        #region Attributes
        private string imageName;
        private MapIndex mapPosition;
        private int heading;

        private Guid ownerId;
        #endregion

        #region Constructor
        public MapObject()
        {
        }
        #endregion

        #region Properties
        public MapIndex MapPosition
        {
            get { return mapPosition; }
            set
            {
                if (mapPosition != value)
                {
                    // If its the same map then just update, otherwise delete and add again.
                    if (mapPosition == null)
                    {
                        mapPosition = value;
                        Map.Add(this);
                        return;
                    }

                    if (value == null)
                    {
                        Map.Delete(this);
                        mapPosition = value;
                        return;
                    }

                    if (mapPosition.MapId == value.MapId)
                    {
                        mapPosition = value;
                    }
                    else
                    {
                        Map.Delete(this);
                        mapPosition = value;

                        if( value != null)
                            Map.Add(this);
                    }
                }
            }
        }

        public int Heading
        {
            get { return heading; }
            set { heading = value; }
        }

        public Guid OwnerId
        {
            get { return ownerId; }
            set { ownerId = value; }
        }

        public string ImageName
        {
            get
            {
                if (imageName == "")
                    return @"Generic Counters\Asteriod.gif";
                return imageName;
            }
            set { imageName = value; }
        }
        #endregion

        #region ICloneable Members
        public override object Clone()
        {
            MapObject obj = base.Clone() as MapObject;
            obj.MapPosition = null;

            return obj;
        }
        #endregion
    }
}
